package com.ruoyi.wvp.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wvp.mapper.ImageEventMapper;
import com.ruoyi.wvp.domain.ImageEvent;
import com.ruoyi.wvp.service.IImageEventService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.enums.DeletedEnum;
import com.ruoyi.common.utils.StringUtils;
import java.util.Objects;
/**
 * 督导员图片推送Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@Service
@Slf4j
public class ImageEventServiceImpl extends ServiceImpl<ImageEventMapper,ImageEvent> implements IImageEventService {
    @Autowired
    private ImageEventMapper imageEventMapper;

    /**
     * 查询督导员图片推送
     * 
     * @param id 督导员图片推送主键
     * @return 督导员图片推送
     */
    @Override
    public ImageEvent selectImageEventById(Long id)    {
        return imageEventMapper.selectImageEventById(id);
    }

    /**
     * 查询督导员图片推送列表
     * 
     * @param imageEvent 督导员图片推送
     * @return 督导员图片推送
     */
    @Override
    public List<ImageEvent> selectImageEventList(ImageEvent imageEvent)    {
        return imageEventMapper.selectImageEventList(imageEvent);
    }

    /**
     * 新增督导员图片推送
     * 
     * @param imageEvent 督导员图片推送
     * @return 结果
     */
    @Override
    public int insertImageEvent(ImageEvent imageEvent)    {
        imageEvent.setCreateTime(DateUtils.getNowDate());
        return imageEventMapper.insertImageEvent(imageEvent);
    }

    /**
     * 修改督导员图片推送
     * 
     * @param imageEvent 督导员图片推送
     * @return 结果
     */
    @Override
    public int updateImageEvent(ImageEvent imageEvent)    {
        imageEvent.setUpdateTime(DateUtils.getNowDate());
        return imageEventMapper.updateImageEvent(imageEvent);
    }

    /**
     * 批量删除督导员图片推送
     * 
     * @param ids 需要删除的督导员图片推送主键
     * @return 结果
     */
    @Override
    public int deleteImageEventByIds(Long[] ids)    {
        return imageEventMapper.deleteImageEventByIds(ids);
    }

    /**
     * 删除督导员图片推送信息
     * 
     * @param id 督导员图片推送主键
     * @return 结果
     */
    @Override
    public int deleteImageEventById(Long id)    {
        return imageEventMapper.deleteImageEventById(id);
    }


       @Override
        public Page<ImageEvent> pageList(Page<ImageEvent> page, ImageEvent imageEvent) {
            LambdaQueryWrapper<ImageEvent> queryWrapper = getQueryWrapper(imageEvent);
            return page(page, queryWrapper);
        }

    @Override
    public void freeSpace() {
        imageEventMapper.freeSpace();
    }

    @Override
        public List<ImageEvent> listAll(ImageEvent imageEvent) {
            return list(getQueryWrapper(imageEvent));
        }

        private  LambdaQueryWrapper<ImageEvent> getQueryWrapper(ImageEvent imageEvent) {
            LambdaQueryWrapper<ImageEvent> queryWrapper = Wrappers.lambdaQuery(ImageEvent.class);
            queryWrapper.eq(ImageEvent::getDeleted, DeletedEnum.NOMAL.getValue());

//        事件图片
             if(StringUtils.isNotEmpty(imageEvent.getPicUrl())){
                queryWrapper.eq(ImageEvent::getPicUrl,imageEvent.getPicUrl());
             }
             if(Objects.nonNull(imageEvent.getCreateDate())){
                 queryWrapper.eq(ImageEvent::getCreateDate,imageEvent.getCreateDate());
             }








            return queryWrapper;
        }
}
